﻿<%@ Page Title="" Language="C#" MasterPageFile="~/resumemanager/resume.master" %>
<%@ Import Namespace="TalentPools.Model" %>
<%@ Import Namespace="TalentPools.BLL" %>
<script runat="server">
    private string resumeId;

    public string ResumeId
    {
        get { return ViewState["resumeId"].ToString(); }
        set { ViewState["resumeId"] = value; }
    }
    protected void dlCustom_EditCommand(object source, DataListCommandEventArgs e)
    {
        ViewState["customId"] = dlCustom.DataKeys[e.Item.ItemIndex];
        custom cus = new CustomManager().GetCustom(ViewState["customId"].ToString(), ResumeId);
        txtTitle.Text = cus.tittle;
        txtContent.Text = cus.content;
    }

    protected void dlCustom_DeleteCommand(object source, DataListCommandEventArgs e)
    {

    }

    protected void btnsave_Click(object sender, ImageClickEventArgs e)
    {
        if (CreateCustom())
        {
            DataBind(ResumeId);
        }
    }

    protected void lbtnContinueCustom_Click(object sender, EventArgs e)
    {
        if (CreateCustom())
        {
            txtzitittle.Text = "";
            txtzicon.Text = "";
            DataBind(ResumeId);
        }
    }

    protected void ibtnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (SaveCustom(ViewState["customId"].ToString()))
        {
            DataBind(ResumeId);
        }
    }

    protected void lbtnConAdd_Click(object sender, EventArgs e)
    {
        if (SaveCustom(ViewState["customId"].ToString()))
        {
            DataBind(ResumeId);
            ClientScript.RegisterStartupScript(typeof(string), "", "<scr" + "ipt" + ">next();</sc" + "ript>");    
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["userid"]==null)
            {
                Response.Redirect("~/Default.aspx");
            }
            string resumeId = Request.QueryString["resumeId"];
            ResumeId = resumeId;
            if (resumeId==null || resumeId=="")
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }
    private bool CreateCustom()
    {
        custom cus = new custom();
        cus.tittle = txtzitittle.Text.Trim();
        cus.content = txtzicon.Text.Trim();
        return new CreateresumeManager().createCustom(cus);
    }
    private void DataBind(string resumeId)
    {
        List<custom> list = new CustomManager().GetCustom(resumeId);
        dlCustom.DataSource = list;
        dlCustom.DataBind();
    }
    private bool SaveCustom(string customId)
    {
        custom cus = new custom();
        cus.customId = customId;
        cus.tittle = txtTitle.Text.Trim();
        cus.content = txtContent.Text.Trim();
        cus.resumeId = ResumeId;
        return new alertResumeManager().updatecustom(cus);
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script src="../js/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../js/jquery-1.6.2.min.js" type="text/javascript"></script>
<style type="text/css">
        #add
        {
            display: block;
        }
        #update
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        function next() {
            $("#add").css("display", "block");
            $("#update").css("display", "none");
        }
        $(function () {
            $("<%=ibtnSubmit.ClientID %>").click(function () {
                $("#add").css("display", "block");
                $("#update").css("display", "none");
            })

        })
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div>
        <asp:DataList ID="dlCustom" runat="server" CssClass="tranningList" DataKeyField="customId"
            OnEditCommand="dlCustom_EditCommand" OnDeleteCommand="dlCustom_DeleteCommand">
            <HeaderTemplate>
                <table class="tableMain" style="width: 100%">
                    <tr>
                        <td class="titleStyle" style="text-align: center; width: 70%;">
                            标题
                        </td>
                        <td class="editStyle" style="width: 30%">
                        </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td class="titleStyle" style="text-align: center; width: 70%;">
                        <%#Eval("tittle") %>
                    </td>
                    <td class="editStyle" style="width: 30%">
                        <asp:LinkButton ID="lbtnEdit" runat="server" Text="编辑" CommandName="Edit"></asp:LinkButton>
                        | <asp:LinkButton ID="lbtnDel" runat="server" Text="删除" CommandName="Delete"></asp:LinkButton>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:DataList>
    </div>
    <div id="add">
        <br />
        <span style="height: 25px; font-family: 微软雅黑 宋体; font-size: 14px; text-align: left;">
            新增自定义信息</span>
        <br />
        <br />
        <table class="tableMain">
            <tr>
                <td class="titleStyle">
                    标题:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtzitittle" runat="server" ValidationGroup="five" BorderStyle="None"
                        Width="195px" MaxLength="50"></asp:TextBox>
                </td>
                <td class="valStyle">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    内容:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtzicon" runat="server" TextMode="MultiLine" Height="153px" Width="195px"
                        ValidationGroup="five" BorderStyle="None" MaxLength="3000"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:ImageButton ID="btnsave" runat="server" ImageUrl="~/img/create.gif" 
                        onclick="btnsave_Click" />
                    <asp:LinkButton ID="lbtnContinueCustom" runat="server" 
                        onclick="lbtnContinueCustom_Click">保存并继续添加自定义内容</asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
    <div id="update">
        <span style="width: 90%; height: 25px; font-family: 微软雅黑 宋体; font-size: 14px; color: #000;
            text-align: left;">修改自定义信息</span>
        <table class="tableMain">
            <tr>
                <td class="titleStyle">
                    标题:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtTitle" runat="server" ValidationGroup="five" BorderStyle="None"
                        Width="195px" MaxLength="50"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td class="titleStyle">
                    内容:
                </td>
                <td class="textStyle">
                    <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="153px" Width="195px"
                        BorderStyle="None" MaxLength="3000"></asp:TextBox>
                </td>
                <td class="valStyle">
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:ImageButton ID="ibtnSubmit" runat="server" ImageUrl="~/img/create.gif" 
                        onclick="ibtnSubmit_Click" />
                    <asp:LinkButton ID="lbtnConAdd" runat="server" onclick="lbtnConAdd_Click">保存修改并继续添加自定义内容</asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
